package gui.applets;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Panel;

class ButtonPanel extends Panel {
	ButtonPanel(String id) {
		this.setLayout(new BorderLayout());
		this.add("Center", new Button(id));
	}
}

public class AppletCardLayout extends Applet {
	Button first = new Button("First");
	Button second = new Button("Second");
	Button third = new Button("Third");

	Panel cards = new Panel();
	CardLayout cl = new CardLayout();

	public void init() {
		this.setLayout(new BorderLayout());
		
		Panel p = new Panel();
		p.setLayout(new FlowLayout());
		p.add(first);
		p.add(second);
		p.add(third);
		this.add("North", p);
		
		cards.setLayout(cl);
		cards.add("First card", new ButtonPanel("The first One"));
		cards.add("Second card", new ButtonPanel("The second One"));
		cards.add("Third card", new ButtonPanel("The third One"));
		this.add("Center",cards);
	}
	
	
	public boolean action(Event evt,Object obj){
		if(evt.target.equals(first)){
			cl.first(cards);
		}else if(evt.target.equals(second)){
			cl.first(cards);
			cl.next(cards);
		}else if(evt.target.equals(third)){
			cl.last(cards);
		}else
			return super.action(evt, obj);
		return true;
		
	}

}
